<?php

namespace App\Http\Controllers;

use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class ProfileController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable|\Illuminate\Http\RedirectResponse
     */
    public function index()
    {
        /** @var User $user */
        $user = Auth::user();

        if ($user->location) {
            return redirect()->route('index');
        }

        return view('h5.profile', compact('user'));
    }

    public function update(Request $request)
    {
        /** @var User $user */
        $user = Auth::user();

        $user->location = $request->get('location');
        // $user->political_status = $request->get('status');

        $user->save();

        return redirect($request->get('redirect_url') ?? route('index'));
    }
}
